﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;
using System.IO;
namespace Com.CMS263.BLL
{
    /// <summary>
    /// 处理标签的类，自动用相关数据替换标签
    /// </summary>
    public class TagsHandler : IHttpModule
    {
        #region IHttpModule 成员

        public void Dispose()
        {
          
        }

        public void Init(HttpApplication context)
        {
          
           
           // context.PreSendRequestContent += new EventHandler(context_PreSendRequestContent);
        }

        void context_PreSendRequestContent(object sender, EventArgs e)
        {
             HttpApplication application = (HttpApplication)sender;
            HttpContext ctx = application.Context;

            string url = ctx.Request.Path;
            string host = ctx.Request.Url.ToString().ToLower();
            string ext = url.Split('.')[url.Split('.').Length - 1];

            if ((ext.ToLower() == "aspx" || ext.ToLower() == "html" || ext.ToLower() == "htm"))
            {
                ctx.Response.OutputStream.Flush();
              
                Stream ReceiveStream = ctx.Response.OutputStream;
                
                StreamReader readStream = new StreamReader(ReceiveStream, System.Text.Encoding.UTF8);
                Char[] read = new Char[256];
                int count = readStream.Read(read, 0, 256);
                string str = null;
                while (count > 0)
                {
                    str += new String(read, 0, count);
                    count = readStream.Read(read, 0, 256);
                }
                readStream.Close();



                ctx.Response.Clear();
                ctx.Response.Write(str);
                ctx.Response.End();
            }
        }

       

      

       
      
        
        #endregion

     

    }
}
